package com.wlr.blog.web.common.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wlr.blog.web.common.entity.Article;
import com.wlr.blog.web.common.entity.PageInfo;
import com.wlr.blog.web.common.entity.WebsiteConfig;
import com.wlr.blog.web.common.mapper.ArticleMapper;
import com.wlr.blog.web.common.mapper.PageInfoMapper;
import com.wlr.blog.web.common.mapper.WebsiteConfigMapper;
import com.wlr.blog.web.common.service.WebSiteService;
import com.wlr.blog.web.common.vo.WebInitInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/11/6 18:03
 */
@Service
public class WebSiteServiceImpl implements WebSiteService {
    @Autowired
    WebsiteConfigMapper websiteConfigMapper;
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    PageInfoMapper pageInfoMapper;

    @Override
    public List<WebsiteConfig> getWebSiteConfigList() {
        return null;
    }

    /**
     * 获取网站初始化信息
     *
     * @return 网站初始化信息
     */
    @Override
    public WebInitInfoVo getWebInitInfo() {
        WebsiteConfig websiteConfig = websiteConfigMapper.selectById(1);
        WebInitInfoVo result = new WebInitInfoVo();
        List<Article> articles = articleMapper.selectList(Wrappers.emptyWrapper());
        List<PageInfo> pageInfos = pageInfoMapper.selectList(Wrappers.emptyWrapper());
        result.setArticleCount(articles.size());
        result.setViewsCount(websiteConfig.getViewCount());
        result.setCategoryCount(10);
        result.setWebsiteConfig(websiteConfig);
        result.setPageList(pageInfos);
        return result;
    }
}
